package me.zhengjie.modules.hanzi.rest;

import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.hanzi.service.GameService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/games")
@RequiredArgsConstructor
public class GameController {
    private final GameService gameService;
    
    @GetMapping("/{gameType}")
    public ResponseEntity<Map<String, Object>> getGameData(
            @PathVariable String gameType,
            @RequestParam(required = false) Integer level) {
        try {
            Map<String, Object> result = new HashMap<>();
            result.put("success", true);
            result.put("data", gameService.getGameData(gameType, level));
            return ResponseEntity.ok(result);
        } catch (IllegalArgumentException e) {
            Map<String, Object> error = new HashMap<>();
            error.put("success", false);
            error.put("message", e.getMessage());
            return ResponseEntity.badRequest().body(error);
        }
    }
} 